package menupopupplugin2.popup.actions;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

public class AutomaticalOrManualPage extends CustomWizardPage {
	private Composite container;
	protected Button rdAutomatic;
	protected Button rdManual;

	public AutomaticalOrManualPage() {
		super("AutomaticalOrManual");
		setTitle("Automatical or manual generate page");
		setDescription("This page for choose what you want, automatically or manual generate "
				+ "the source code.");
	}

	@Override
	public void createControl(Composite parent) {
		container = new Composite(parent, SWT.NULL);
		GridLayout layout = new GridLayout();
		container.setLayout(layout);
		layout.numColumns = 1;

		RdSelectionListener rdSelectionListener = new RdSelectionListener();
		rdAutomatic = new Button(container, SWT.RADIO);
		rdAutomatic.setText("Automatically generate all of source code");
		rdAutomatic.setData("Automatic");
		rdAutomatic.addSelectionListener(rdSelectionListener);

		rdManual = new Button(container, SWT.RADIO);
		rdManual.setText("Manually generate model layer source code");
		rdManual.setData("Manual");
		rdManual.addSelectionListener(rdSelectionListener);

		// Required to avoid an error in the system
		setControl(container);
		setPageComplete(false);

	}

	private class RdSelectionListener implements SelectionListener {

		@Override
		public void widgetDefaultSelected(SelectionEvent e) {
			System.out.println("Default Selected");
		}

		@Override
		public void widgetSelected(SelectionEvent e) {
			if (rdAutomatic.getSelection())
				setPageComplete(true);
			else
				setPageComplete(false);
		}
	}

	@Override
	public boolean isFinish() {
		if (rdManual.getSelection())
			return true;

		return false;
	}

	public IWizardPage getNextPage() {
		// if (rdAutomatic.getSelection())
		// return getWizard().getPage("Three");

		return super.getNextPage();
	}
}
